﻿using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Kaspersky.Test.RecursiveLinkLogger
{
    /// <summary>
    /// Searches for HTML links in a string using a Regex
    /// </summary>
    public abstract class RegexLinkExtractorBase : ILinkExtractor
    {
        /// <summary>
        /// A Regex to be used for searching
        /// </summary>
        protected Regex UrlRegex;

        /// <summary>
        /// Searches for links in a string
        /// </summary>
        /// <param name="s">input string</param>
        /// <returns>IEnumerable of links</returns>
        public IEnumerable<string> ExtractLinksFromString(string s)
        {
            for (var match = this.UrlRegex.Match(s); match.Success; match = match.NextMatch())
            {
                yield return match.Groups[1].Value;
            }
        }
    }
}
